﻿//
// Developped by Clint Rutkas
// http://www.betterthaneveryone.com
//
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace ToDoList
{
    public class Win32
   {
		// window positioning flags
        static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
        static readonly IntPtr HWND_NOTOPMOST = new IntPtr(-2);
        static readonly IntPtr HWND_TOP = new IntPtr(0);
        static readonly IntPtr HWND_BOTTOM = new IntPtr(1);

		public const uint SWP_NOMOVE = 0x2;
		public const uint SWP_NOSIZE = 0x1;
		public const uint SWP_SHOWWINDOW = 0x40;

		// http://www.developer.com/net/csharp/article.php/3347251
		// and http://msdn.microsoft.com/en-us/library/ms633545(VS.85).aspx
        // AND http://pinvoke.net/default.aspx/user32.SetWindowPos
		[DllImport("user32.dll", EntryPoint = "SetWindowPos")]
		public static extern bool SetWindowPos(
            IntPtr hWnd, // window handle
            IntPtr hWndInsertAfter, // placement-order handle
			int X, // horizontal position
			int Y, // vertical position
			int cx, // width
			int cy, // height
			uint uFlags);

		public static void SetWindowInBack(IntPtr handle)
		{
            SetWindowPos(handle,
               HWND_NOTOPMOST,
               0, 0, 0, 0,
               SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);

			SetWindowPos(handle,
               HWND_BOTTOM,
			   0, 0, 0, 0,
			   SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
		}

		public static void SetWindowInFront(IntPtr handle)
		{
			SetWindowPos(handle,
               HWND_TOPMOST,
			   0, 0, 0, 0,
			   SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
		}
	}
}
